import organizeApi from 'api/organize'

// state
let state = {
  list: [],
  company_list: {},
  organize_info: {},
  code: {},
  getData: {}  // 传递url中参数
}

// getters
const getters = {
  organize_list: state => state.list,
  organize_Company_list: state => state.company_list,
  organize_info: state => state.organize_info,
  organize_code: state => state.code,
  update_url: state => state.getData
}

// actions
const actions = {
  organize_list ({ commit, state }, params) {  // IP类型列表api
    organizeApi.list(params).then((json) => {
      commit('ORGANIZE_LIST', {
        params: params,
        data: json.data
      })
    })
  },
  organize_Company_list ({ commit, state }, params) { // 获取公司类型列表api
    organizeApi.companyList(params).then((json) => {
      commit('ORGNIZE_COMPANY_LIST', {
        params: params,
        data: json.data
      })
    })
  },
  organize_info ({ commit, state }, params) { // 获取认证信息api
    organizeApi.info(params).then((json) => {
      commit('ORGANIZE_INFO', {
        params: params,
        data: json.data
      })
    })
  },
  organize_code ({ commit, state }, params) { // 校验验证码api
    organizeApi.code(params).then((json) => {
      commit('ORGANIZE_CODE', {
        params: params,
        data: json.data
      })
    })
  },
  update_url ({commit}, params) {
    commit('UPDATE_URL', params)
  }
}
// mutations
const mutations = {
  ORGANIZE_LIST (state, { data, params }) {
    state.list = data
  },
  ORGNIZE_COMPANY_LIST (state, { data, params }) {
    state.company_list = data
  },
  ORGANIZE_INFO (state, { data, params }) {
    state.organize_info = data
  },
  ORGANIZE_CODE (state, data) {
    // state.code = data
    state.code = Object.assign({}, data)
  },
  UPDATE_URL (state, params) {
    state.getData = params
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
